﻿using System.Collections.Generic;
using System.Text;
using System.Web;
using SlamCms.Common;

namespace SlamCms.Web.Mvc
{
	public class IncludeRenderer : IHtmlString
	{
		public IList<IHtmlString> includes;

		public IncludeRenderer()
		{
			includes = new List<IHtmlString>();
		}

		public IncludeRenderer Add(IHtmlString include)
		{
			if (include == null)
				return this;

			this.includes.Add(include);
			return this;
		}

		public string ToHtmlString()
		{
			var sb = new StringBuilder();
			foreach (var include in includes)
			{
				var html = include.ToHtmlString();
				if (!html.IsNullOrWhiteSpace())
					sb.AppendLine(html);
			}

			return sb.ToString();
		}
	}
}
